{extend name="sitehome@style/base"/}
{block name="resources"}
{/block}
{block name="main"}

<div class="layui-form">
  	<div class="layui-form-item">
    	<label class="layui-form-label"><span class="required">*</span>SMTP服务器</label>
	    <div class="layui-input-block">
	      <input type="text" name="server" required placeholder="请输入SMTP 服务器" autocomplete="off" class="layui-input nc-len-long" lay-verify="server" {notempty name="$list"}value="{$list['server']}{/notempty}">
	    </div>
	  	<p class="layui-form-mid layui-word-aux">设置 SMTP 服务器的地址，如 smtp.163.com</p>
  	</div>
  	<div class="layui-form-item">
	    <label class="layui-form-label" ><span class="required">*</span>SMTP端口</label>
	    <div class="layui-input-block">
	      <input type="number" name="port" required lay-verify="port" placeholder="请输入SMTP 端口" autocomplete="off" class="layui-input nc-len-long" {notempty name="$list"}value="{$list['port']}{/notempty}">
	    </div>
	  	<p class="layui-form-mid layui-word-aux">设置 SMTP 服务器的端口，默认为 25</p>
  	</div>
  	<div class="layui-form-item">
	    <label class="layui-form-label"><span class="required">*</span>发信人邮件地址</label>
	    <div class="layui-input-block">
	      <input type="text" name="email"  required  placeholder="请输入邮件地址" autocomplete="off" class="layui-input nc-len-long" lay-verify="email" {notempty name="$list"}value="{$list['email']}{/notempty}">
	    </div>
	  	<p class="layui-form-mid layui-word-aux">使用SMTP协议发送的邮件地址，如 niucloud@163.com</p>
  	</div>
  	<div class="layui-form-item">
  		<label class="layui-form-label"><span class="required">*</span>SMTP身份验证用户名</label>
	    <div class="layui-input-block">
	      <input type="text" name="username" autocomplete="off" class="layui-input nc-len-long" required lay-verify="username" placeholder="请输入SMTP 身份验证用户名" {notempty name="$list"}value="{$list['username']}{/notempty}">
	    </div>
	  	<p class="layui-form-mid layui-word-aux">如 niucloud@163.com</p>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>SMTP身份验证密码</label>
	    <div class="layui-input-block">
	      	<input type="password" name="password" autocomplete="off" class="layui-input nc-len-long" required lay-verify="password" placeholder="请输入SMTP 身份验证密码" {notempty name="$list"}value="{$list['password']}{/notempty}">
	    </div>
		<p class="layui-form-mid layui-word-aux">niucloud@163.com邮件的密码，如 123456</p>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">是否开启</label>
		<div class="layui-input-block">
			<input type="checkbox" name="status" value="1" lay-skin="switch" lay-filter="switchTest"  {if condition="$status eq '1'"}checked{/if}>
		</div>
	</div>
	<div class="nc-form-row">
		<button class="layui-btn" lay-submit lay-filter="*">保存</button>
		<button class="layui-btn layui-btn-primary" onclick="javascript:history.go(-1);">返回</button>
	</div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
layui.use('form', function(){
	var form = layui.form;
	var repeat_flag = false;//防重复标识
	form.on('submit(*)', function(data){
		var field = data.field;
		if(repeat_flag) return;
		repeat_flag = true;
		$.ajax({
			type : "post",
			url : '{:addon_url("Email://sitehome/Config/index")}',
			data : field,
			dataType : "JSON",
			success : function(res) {
				repeat_flag = false;
				layer.msg(res.message);
			}
		});
	});

	form.verify({
		username: function(value, item){
			if(value == ''){
				return '请设置SMTP 身份验证用户名';
			}
			if(/(^\_)|(\__)|(\_+$)/.test(value)){
			return '用户名首尾不能出现下划线\'_\'';
			}
			if(/^\d+\d+\d$/.test(value)){
			return '用户名不能全为数字';
			}
		},
		server: function(value,item){
			if(value == ''){
				return '请设置邮件服务器地址';
			}
		},
		port:function(value,item){
			if(value == ''){
				return '请设置SMTP 端口';
			}
		},
		password:function(value,item){
			if(value == ''){
				return '请设置SMTP 身份验证密码';
			}
		}
	}); 
});
</script>
{/block}